﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using ALE_Server.Plugin;

namespace ALE_Server.Plugin.Notifiers
{
    public class FileNotifier : Notifier
    {
        public FileNotifier(string uri)
            : base(uri)
        {
        }

        public override void Init(string uri)
        {
           
        }

        public override void NotifySubscriber(ALE_Server.EC.ECReports reports)
        {
            try
            {
                if (File.Exists(m_Uri.ToString()))
                {
                    File.Delete(m_Uri.ToString());
                }

                FileStream FStream = new FileStream(m_Uri.ToString(), FileMode.Create);
                WriteToOutputStream(reports, FStream);
                FStream.Close();
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public override string GetURIFromFields()
        {
            return "file://" + m_Uri;
        }
    }
}
